import { AEvent } from "aomd-utils/src/event/AEvent";
/**
 * 粘贴
 *
 * @class Paste
 */
class Paste extends AEvent {
  constructor(option) {
    super();
    this._event = {
      'html': [],
      'file': [],
      'plain': []
    }
    this.dom = option && document.getElementById(option.id) || option.dom
    this.dom.addEventListener('paste', this._onpaste.bind(this))
  }
  _onpaste(e) {
    console.log('event')
    var e = event || e
    for (var item of e.clipboardData.items) {
      if (item.kind == 'string') {
        if (item.type.indexOf('plain') > -1) {
          this._getPlain(item)
        } else if (item.type.indexOf('html') > -1) {
          this._getHtml(item)
        }
      } else if (item.kind == 'file') {
        this._getFile(item)
      }
    }
  }
  _getHtml(item) {
    var _this = this;
    item.getAsString(function (content) {
      _this._emit('html', content);
    })
  }
  _getPlain(item) {
    var _this = this;
    item.getAsString(function (content) {
      _this._emit('plain', content);

    })
  }
  _getFile(item) {
    var tempFile = item.getAsFile();
    this._emit('file', tempFile);
  }
}

export {
  Paste
}